﻿//++
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// Module Name:
//
//  Errors.cs
//    
// Abstract:
//
//  This module implements the Exception-derived classes used by the Scheduler.
//
//--

using System;
using System.Diagnostics;
using System.Runtime.Serialization;

using Microsoft.OfficeCommunicationsServer.Applications.Common;

namespace Microsoft.EnhancedReminders.Scheduler
{
    /// <summary>
    /// Returned when a task fails.
    /// </summary>
    [Serializable]
    internal class TaskFailedException : Exception
    {
        private readonly Context _context;

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="context">Logging context</param>
        /// <param name="message">A message describing the cause of the error</param>
        internal TaskFailedException(Context context, string message)
            : base(message)
        {
            Debug.Assert(context != null, "context != null");

            _context = context;
        }

        /// <summary>
        /// Returns the logging context associated with this error.
        /// </summary>
        internal Context Context
        {
            get
            {
                return _context;
            }
        }
    }

    /// <summary>
    /// Returned when an Exchange task fails.
    /// </summary>
    [Serializable]
    internal class ExchangeTaskFailedException : TaskFailedException
    {
        // The EWS response code associated with this error
        private readonly ResponseCodeType _responseCode;

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="context">Logging context</param>
        /// <param name="responseCode">The EWS Response code associated with this error</param>
        /// <param name="message">A message describing the cause of the error</param>
        internal ExchangeTaskFailedException(Context context, ResponseCodeType responseCode, string message)
            : base(context, message)
        {
            _responseCode = responseCode;
        }

        /// <summary>
        /// Returns the EWS response code associated with this error.
        /// </summary>
        internal ResponseCodeType ResponseCode
        {
            get
            {
                return _responseCode;
            }
        }
    }
}
